package com.gopay.bis.spdb.expay.operation;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.csii.payment.client.core.MerchantSignVerify;
import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.spdb.expay.SpdbMessageExPay;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;

/**
 * 浦发快捷支付签名验签类
 * @author w_jiqing
 * @date 2016/04/12
 */
public class SpdbExPayCertHelper implements ICertHelper{

	public String sign(BaseMessage baseMessage) throws GopayException {
		try {
			SpdbMessageExPay message = (SpdbMessageExPay) baseMessage;
			BankLogUtils.printExPaySignSendLog(message);
			String signMsg = MerchantSignVerify.merchantSignData_ABA((String) message.getPlainMessage());
			return signMsg;
		} catch (Exception e) {
			BankLogUtils.printExPaySignExceptionLog(baseMessage, e);
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E6029);
		}
	}

	public Object verify(BaseMessage baseMessage) throws GopayException {
		try {
			SpdbMessageExPay message = (SpdbMessageExPay) baseMessage;
			message.setOutStlmCd(BankConstants.BANK_LOGO_SPDB);
			boolean isVeriyPass = false;
			//BankLogUtils.printExPayVerifySendLog(baseMessage);
			//BankLogUtils.printExPayVerifySignatureLog(baseMessage, message.getSignMessage());
			isVeriyPass = MerchantSignVerify.merchantVerifyPayGate_ABA(message.getSignMessage(), message.getPlainMessage());
			BankLogUtils.printExPayVerifyResultLog(baseMessage, isVeriyPass);
			return isVeriyPass;
		} catch (Exception e) {
			BankLogUtils.printExPayVerifyExceptionLog(baseMessage, e);
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E6079);
		}
	}

}
